package aconcagua.measure

class NotProportionalDerivedUnit extends DerivedUnit {
	private nameForOne;
	private nameForMany;
	private sign;
	private baseUnit;
	private conversionClosure;
	private reciprocalConversionClosure;

	// (class) instance creation
	public NotProportionalDerivedUnit(aBaseUnit, aConversionClosure, aReciprocalConversionClosure, aName) {
		baseUnit = aBaseUnit;
		conversionClosure = aConversionClosure;
		reciprocalConversionClosure = aReciprocalConversionClosure;
		nameForOne = aName;
		nameForMany = nameForManyFrom(aName);
		sign = defaultSign();
	}

	public NotProportionalDerivedUnit(aBaseUnit, aConversionClosure, aReciprocalConversionClosure, aName, aSign) {
		baseUnit = aBaseUnit;
		conversionClosure = aConversionClosure;
		reciprocalConversionClosure = aReciprocalConversionClosure;
		nameForOne = aName;
		nameForMany = nameForManyFrom(aName);
		sign = aSign;
	}

	public NotProportionalDerivedUnit(aBaseUnit, aConversionClosure, aReciprocalConversionClosure, aNameForOne, aNameForMany, aSign) {
		baseUnit = aBaseUnit;
		conversionClosure = aConversionClosure;
		reciprocalConversionClosure = aReciprocalConversionClosure;
		nameForOne = aNameForOne;
		nameForMany = aNameForMany;
		sign = aSign;
	}

	// accessing
	@Override
	public baseUnit() {
		return baseUnit;
	}

	@Override
	public nameForMany() {
		return nameForMany;
	}

	@Override
	public nameForOne() {
		return nameForOne;
	}

	@Override
	public sign() {
		return sign;
	}

	// converting
	@Override
	public convertAmountToBaseUnit(aNumber) {
		return conversionClosure.call(aNumber);
	}

	// converting - private
	@Override
	protected convertAmountFromBaseUnit(aNumber) {
		return reciprocalConversionClosure.call(aNumber);
	}
}
